<%@page import="java.text.NumberFormat"%>
<%@page import="com.is.control.ParamReasonTypeGSControl"%>
<%@page import="com.is.control.ParamReasonTypeControl"%>
<%@page import="com.is.control.AttendanceDetailControl"%>
<%@page import="com.is.control.AttendanceTimeControl"%>
<%@page import="com.is.util.DateTime"%>
<%@page import="com.is.model.User"%>
<%@page import="com.is.control.StudentControl"%>
<%@page import="com.is.model.Student"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.model.ParamCourse"%>
<%@page import="com.is.control.CourseClassControl"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="java.util.List"%>
<%@page import="com.is.model.ParamStuyear"%>
<%@page import="com.is.control.ParamClassControl"%>
<%@page import="com.is.model.ParamClass"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../resources/css/all.css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="../../resources/js/WebCalendar.js"></script>
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<script type="text/javascript" src="../../resources/js/iframeTools.js"></script>
<script type="text/javascript">
$(function(){
	var block = $("#magic_block");
	if($(".active a").position()){
		block.css("top",$(".active a").position().top+10)
		.data("oriTop",$(".active a").position().top)
	}
	$(".nav ul li").find("a").hover(
		function(){
			var $this = $(this);
			var newTop = $this.position().top;
			block.stop().animate({
				top:newTop+10
			})
		},
		function(){
			block.stop().animate({
				top:block.data("oriTop")+10
			})
		}
	)
	var h = $(".right").height();
	$(".left").height(h);
	$(".update").click(function(){
		$.dialog.open("/InterStu/update_info.jsp",{width:460,height:400,title:"个人信息"});
	})
	$('img').error(function(){
		this.src = "/InterStu/resources/image/man.GIF";
	})
	/*二级联动菜单*/
	$("[name='stuyear']").change(function(){
		var temVal = $(this).val();
		if(temVal!= "%%"){
			$.ajax({
				type:"post",
				cache:false,
				url:"../students/printClass.jsp",
				dataType:"html",
				data:{
					gradeYear: temVal
				},
				success:function(data){
					$("[name='classId']")[0].options.length=1;
					$("[name='classId']").append(data);
				}
			})
		} else{
			$("[name='classId']")[0].options.length=1;
		}
	})
})	
</script>
<script type="text/javascript">

</script>
<title>留学生预科班</title>
</head>
<body>
<%
    //此页面需要的参数courseId
    User cu =(User)session.getAttribute("user"); 
%>            
<div class="header">
	<div class="title pr">
    	<a href="javascript:void(0);"><span class="update pa">个人信息</span></a>
        <span class="logout pa"><a class="hide" href="/InterStu/login/logout.jsp">退出</a></span>
    </div>
</div>
<div class="main">
	<div class="left"> 
	    <div class="infomation">
			<div class="photo">
			<%
			String picUrl = cu.getPicUrl();
			%>
				<img width='60' height="60" src = "<%=picUrl %>"   />
			</div>
			<div class="welcome">
				<%=cu.getName() %>,<br/>
				欢迎您使用！
			</div>
		</div>  	   	  	 	
    	<div class="nav">
        	<ul>	
        		<li class="pa" id="magic_block"></li>
            	<%if(cu!=null&&cu.getRole().equals("1")){ %>
                <li><a href="/InterStu/pages/stuyear/stuyear_start.jsp">新学期设置</a></li>
                <li><a href="/InterStu/pages/users/user_all.jsp">用户管理</a></li>
                <%} %>
                <li class="active"><a href="/InterStu/pages/students/student_add.jsp">学生管理</a></li>
                <li ><a href="/InterStu/pages/dictation/dictation_add.jsp">学生考核</a></li>
                <%if(cu!=null&&cu.getRole().equals("1")){ %>
                <li><a href="/InterStu/pages/assess/teacher_assess.jsp">教职人员管理</a></li>
                <%} %>
            </ul>
        </div>
        </div>
        <div class="right">
    	<div class='r1'>
	    	<table class="student tab">
			    <tr>
			    	<%if(cu!=null&&cu.getRole().equals("1")){ %>
			    	<td>
			    		<a href="/InterStu/pages/students/student_add.jsp">添加学生</a>
					</td>
					<%} %>
					<td>
						<a href="/InterStu/pages/students/student_admin.jsp?id=<%=cu.getId() %>">查看学生</a>
					</td>
					<td>
						<a class='current' href="/InterStu/pages/attendance/attendance_add.jsp">学生出勤</a>
					</td>
			    </tr>
			 </table>
	    
<%
         // 单个学生所有课程出席情况
         //单个班级所有科目分数
         int classId = ParamUtil.getInt(request, "classId",24);
		String time1 = DateTime.SimpleDate();
		String time2 = DateTime.SimpleDate();
		int stuyear = ParamStuyearControl.getCurrentStuyearId();
         int usingStuyear = ParamUtil.getInt(request, "stuyear",stuyear);
         ParamStuyear usingPS = ParamStuyearControl.getStuyear(usingStuyear);
         
         if(usingStuyear!=0&&usingPS!=null){
 	        // System.out.print(usingPS.getStuyear());System.out.print(usingPS.getStartTime());
 	         time1 = ParamUtil.getString(request,"time1",usingPS.getStartTime());//默认为使用学期开学时间
 	        if(session.getAttribute("gradeYear2")!=null&&!session.getAttribute("gradeYear2").equals(usingStuyear+"")){
	        	 time1 = usingPS.getStartTime();
	        }
 	     }else{
 		    time1 = ParamUtil.getString(request,"time1",usingPS.getStartTime());
 	     }
 	   if(stuyear==usingStuyear){
 	        time2 = ParamUtil.getString(request,"time2",DateTime.SimpleDate());
 	   }else{
 		  time2 = ParamUtil.getString(request,"time2",usingPS.getEndTime());
 		  if(session.getAttribute("gradeYear2")!=null&&!session.getAttribute("gradeYear2").equals(usingStuyear+"")){
 			 time2 =usingPS.getEndTime();
	        }
 		   
 	   }
 	  session.setAttribute("gradeYear2", usingStuyear+"");
 	 session.setAttribute("classId2", classId);
      LinkedHashMap<Integer,LinkedHashMap<String,String>> stusAtts = new LinkedHashMap<Integer,LinkedHashMap<String,String>>();
      LinkedHashMap<String,String> stuatt = new LinkedHashMap<String,String>();
        	 %>

 <form action="oneClassAllAttendance.jsp" method="post">
<table class='table'>
 	<caption>请选择：</caption>
 	<tr>
 		<td><select name="stuyear" id="stuyear">
			<option value="%%"  selected="selected">全部</option>
				<% 
					//HashMap map = StudentControl.getGradeYear();
				  List<ParamStuyear> stuyears = ParamStuyearControl.getAllStuyear();
					for(ParamStuyear ps:stuyears){
				%>
					<option value="<%=ps.getId() %>"  <%=(session.getAttribute("gradeYear2") != null && session.getAttribute("gradeYear2").toString().equals(ps.getId()+""))?"selected":"" %>>
						<%=ps.getStuyear() %>
					</option>
				<%	
					}
				%>
			 </select>
		</td>
		<td>
		<select name="classId" id="classId">
		<option value="">全部</option>
			<%
				String grade = (String)session.getAttribute("gradeYear2");
			    String stuy = "@"+grade+"@";
				HashMap map2 = StudentControl.getClassesByStuyear(stuy);
				Iterator it2 = map2.entrySet().iterator();
				while(it2.hasNext()){
				Map.Entry entry2 = (Map.Entry)it2.next();
			%>
			<option value="<%=entry2.getKey()%>" <%=(session.getAttribute("classId2")!=null && session.getAttribute("classId2").toString().equals(entry2.getKey().toString()))?"selected":"" %>><%=entry2.getValue() %></option>
			<%
			} 
			%>
		</select>
		</td>
		<td>开始时间</td>
	   <td><input id="time1" type='text'  name="time1" onclick="SelectDate(this,'','','yyyy-MM-dd')"  readonly style="width:80px;cursor:pointer"  value="<%=time1 %>"/></td>
       <td>结束时间</td>
	   <td><input id="time2" type='text'  name="time2" onclick="SelectDate(this,'','','yyyy-MM-dd')"  readonly style="width:80px;cursor:pointer"  value="<%=time2 %>"/></td>
 		<td>
			<input type="submit" value="查询" />
		</td>
 		<td>
			<input type="button" value="导出查询结果" onclick="window.location.href='exportoneClassAllAttendance.jsp?classId=<%=classId %>&stuyear=<%=usingStuyear %>&time1=<%=time1 %>&time2=<%=time2 %>'" />
		</td>
 	</tr>
 </table>
 </form>
<%
if(classId>0){
	 ParamClass pc = ParamClassControl.getClassById(classId);
	 
%>
 <div class='r2'>
  <form>
 <table class="table">
 <caption><%=pc.getClassName()%>的出勤情况：</caption>
	 <tr>
		 <th>/</th>
		 <%
		        List<CourseClass> ccs = CourseClassControl.getAllCourseClassIdByClassIdAndStuyear(classId, usingStuyear);
		 		for(CourseClass cc:ccs){
		 			ParamCourse ps = ParamCourseControl.getCourseById(cc.getCourseId());
		 			%>
		 			 <th colspan="5"><%=ps.getCourseName() %></th>
		 			<%
		 		}
		 %>
		 <th colspan="3">统计</th>
	 </tr>
 <tbody>
 <tr><td>姓名</td>
       <%for(int i=0;i<ccs.size();i++){ %>
       <td>迟到</td>
       <td>缺勤</td>
       <td>病假</td>
       <td>事假</td>
       <td>缺勤率</td>
       <%} %>
       <td>总点名次数</td>
	   <td>折合总缺勤数</td>
	   <td>折合总缺勤率</td>
 </tr>
 <%
       List<Student> stus = StudentControl.getStudentByClassId(classId+"");
 //System.out.println("DDDD"+usingStuyear);
      for(Student stu:stus){
         int sumTimes=0;
         float qqTimes = 0;
		  %>
		  <tr>
		  <td><%=stu.getChineseName() %></td>
		  <%
		 
		        for(CourseClass nowcc:ccs){
		        	 int countTimes = AttendanceTimeControl.getCount(nowcc.getId(),usingStuyear,time1,time2);
		        	
		        	 float totalQQ=0;
	        		  int totalDM = AttendanceTimeControl.getCount(nowcc.getId(),usingStuyear,"","");
	        		  boolean flag = true;
			          int count2 = AttendanceDetailControl.getCount(2,stu.getId(),nowcc.getId()+"",usingStuyear,time1,time2);
			          int num2 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(2,usingStuyear);
			          if(num2==0){
			        	  flag = false;
			          }else{
			        	  totalQQ+= (float)count2/num2;
			          }
			          int count3 = AttendanceDetailControl.getCount(3,stu.getId(),nowcc.getId()+"",usingStuyear,time1,time2);
			          int num3 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(3,usingStuyear);
			          if(num3==0){
			        	  flag = false;
			          }else{
			        	  totalQQ+= (float)count3/num3;
			          }
			          int count4 = AttendanceDetailControl.getCount(4,stu.getId(),nowcc.getId()+"",usingStuyear,time1,time2);
			          int num4 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(4,usingStuyear);
			          if(num4==0){
			        	  flag = false;
			          }else{
			        	  totalQQ+= (float)count4/num4;
			          }
			          int count5 = AttendanceDetailControl.getCount(5,stu.getId(),nowcc.getId()+"",usingStuyear,time1,time2);
			          int num5 = ParamReasonTypeGSControl.getNumByTypeAndStuyear(5,usingStuyear);
			          if(num5==0){
			        	  flag = false;
			          }else{
			        	  totalQQ+= (float)count5/num5;
			          }
			          float absenceRate = 0;
			          String absencePer="";
			          if(countTimes == 0){
			          	  //flag = false;
			          	   absenceRate = 0;
			          	   absencePer = "0";
			          } else{
			        	  NumberFormat nt = NumberFormat.getPercentInstance();
			        	  nt.setMinimumFractionDigits(2);
			          	  absenceRate = totalQQ/countTimes;
			          	  absencePer =nt.format(absenceRate);
			          }
			          sumTimes+=countTimes;
			          qqTimes+=totalQQ;
		  %>
	  <td><%=flag?count2:"公式有错误或者尚未设置，请联系管理员"%></td>
	  <td><%=flag?count3:"公式有错误或者尚未设置，请联系管理员"%></td>
	  <td><%=flag?count4:"公式有错误或者尚未设置，请联系管理员"%></td>
	  <td><%=flag?count5:"公式有错误或者尚未设置，请联系管理员"%></td>
	  <td><%=flag?absencePer:"公式有错误或者尚未设置，请联系管理员"%></td>
		 <%
		 //stuatt.put("pc"+nowcc.getCourseId(),nowcc.getCourseId()+"");
		 //]]stuatt.put("pc"+nowcc.getCourseId(),nowcc.getCourseId()+"");
		 stuatt.put(nowcc.getCourseId()+"count2"+stu.getId(),count2+"");
		 stuatt.put(nowcc.getCourseId()+"count3"+stu.getId(),count3+"");
		 stuatt.put(nowcc.getCourseId()+"count4"+stu.getId(),count4+"");
		 stuatt.put(nowcc.getCourseId()+"count5"+stu.getId(),count5+"");
		 stuatt.put(nowcc.getCourseId()+"absencePer"+stu.getId(),absencePer+"");
		        } 
		  NumberFormat nt = NumberFormat.getPercentInstance();
    	  nt.setMinimumFractionDigits(2);
    	  String totalAbsencePer="";
    	  float totalAbsenceRate=0;
    	 totalAbsenceRate = qqTimes/sumTimes;
    	  totalAbsencePer =nt.format(totalAbsenceRate);
		 %>
		 <td><%=sumTimes %></td>
		 <td><%=qqTimes %></td>
		 <td><%=totalAbsencePer %></td>
		 </tr>
		 <%
		//stuatt.put(stu.getId()+"totalAbsenceRate",totalAbsenceRate+"");
		stuatt.put(stu.getId()+"totalAbsencePer",totalAbsencePer+"");
		stuatt.put(stu.getId()+"sumTimes",sumTimes+"");
		stuatt.put(stu.getId()+"qqTimes",qqTimes+"");
		 stusAtts.put(stu.getId(),stuatt);
      } 
      session.removeAttribute("stuAtts");
      session.setAttribute("stuAtts",stusAtts);
      %>
 </tbody>
 </table>
 <br/>
 </form>
 </div>
        	 <%
         }else{
        	 out.print("请选择班级");
         }
 %>

     </div>
</div>
</div>
<div class="footer">
	<p>版权所有：东北师范大学留学生预科部&nbsp;&nbsp;  蓝旭工作室开发</p>
</div>
</body>
</html>